<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
    <style>
        div{
            width:50px;
            height:50px;
            background-color: cadetblue;
            position: fixed;
            right:30px;
            bottom:100px;
            display: none;
        }
        p{
            height: 100px;
        }
    </style>
<body>
    <p>1</p>
    <p>1</p>
    <p>1</p>
    <p>1</p>
    <p>1</p>
    <p>1</p>
    <p>1</p>
    <p>1</p>
    <p>1</p>
    <div>返回顶部</div>
    <script>
        var div=document.querySelector('div');
        var html=document.documentElement;
        var body=document.body;
        body.onscroll=function(){
            var scrollTop=html.scrollTop;
            if(scrollTop>=150){
                div.style.display='block';
            }
            else{ 
                div.style.display='none';
            }
        }
    </script>
</body>
</html>